<?php
namespace App\Http\Controllers\Admin\Qudao;

use App\Service\Admin\Qudao\ShopService;
use Illuminate\Http\Request;

class ShopController extends BaseController
{
    //渠道商

    public function __construct(ShopService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getIndex(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $isauth = $request->post('isauth', 0);
        $res = $this->db->getList($isauth, $pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

//    //审核OK
//    public function setAuth(Request $request)
//    {
//        $id = $request->post('id', 0);
//        $res = $this->db->setAuth($id);
//        if ($res['code'] < 0) {
//            return $this->toJson(-2, $res['msg']);
//        }
//        return $this->toJson();
//    }

    //审核OK
    public function setAuth(Request $request)
    {
        $id = $request->post('id', 0);
        $level = $request->post('level', 0);
        $res = $this->db->setAuth($id, $level);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //充值记录
    public function rechargeList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $res = $this->db->rechrgeList($uid);
        if ($res['code'] < 0) {
            return $this->toJson($res['code'], $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //提现记录
    public function tixianList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $res = $this->db->tixianList($uid);
        if ($res['code'] < 0) {
            return $this->toJson($res['code'], $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //消费记录
    public function costList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $res = $this->db->costList($uid);
        if ($res['code'] < 0) {
            return $this->toJson($res['code'], $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //团队列表
    public function teamList(Request $request)
    {
        $pid = $request->post('pid', 0);
        $res = $this->db->teamList($pid);
        if ($res['code'] < 0) {
            return $this->toJson($res['code'], $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //团队收益列表
    public function teamCostList(Request $request)
    {
        $uid = $request->post('uid', 0);
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->teamCostList($pages, $uid);
        if ($res['code'] < 0) {
            return $this->toJson($res['code'], $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //提现审核列表
    public function txAuthList(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->txAuthList($pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //提现审核修改
    public function txAuthModify(Request $request)
    {
        $id = $request->post('id', 0);
        $auth = $request->post('auth', 0); //1拒绝，2通过
        if (!in_array($auth, [1, 2])) {
            return $this->toJson(-2, '参数错误');
        }
        $res = $this->db->txAuthModify($id, $auth);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //卡号列表
    public function bankList(Request $request)
    {
        $pages['start'] = $request->post('start', 1);
        $pages['limit'] = $request->post('limit', 10);
        $uid = $request->post('uid', 0);
        $res = $this->db->bankList($pages, $uid);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //卡号默认
    public function bankDefaultModify(Request $request)
    {
        $id = $request->post('id', 0);
        $res = $this->db->bankDefaultModify($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}